﻿@using DBMS.Models

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Table Structure</h2>

@if (ViewBag.Columns.Count == 0)
{
    <div>This table contains no columns.</div>
}
else
{
    <table>
        <tbody>
            @foreach (Column column in ViewBag.Columns)
            {
                <tr>
                    @if (column.PrimaryKey)
                    {
                        <td>P</td>
                    }
                    else
                    {
                        <td>-</td>
                    }
                    <td>@column.Name</td>
                    <td>@column.Type</td>
                    <td>
                        @Html.ActionLink("Primary", "SetPrimary", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = ViewBag.Table.Index.ToString(), columnId = column.Index.ToString() }, null)
                        @Html.ActionLink("FK", "SetForeign", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = ViewBag.Table.Index.ToString(), columnId = column.Index.ToString() }, null)
                        @Html.ActionLink("Edit", "EditColumn", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = ViewBag.Table.Index.ToString(), columnId = column.Index.ToString() }, null)
                        @Html.ActionLink("Drop", "DeleteColumn", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = ViewBag.Table.Index.ToString(), columnId = column.Index.ToString() }, null)
                    </td>
                </tr>
            }
        </tbody>
    </table>
}

<div>@Html.ActionLink("Add New Column", "CreateColumn", "Columns", new { databaseId = ViewBag.Database.Index.ToString(), tableId = ViewBag.Table.Index.ToString() }, null)</div>

